package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Salesagent;
import org.hxyjs.entity.School;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.SchoolService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/schoolController")
public class SchoolController {
	@Resource
	SchoolService schoolService;
	@RequestMapping("/getAllSchool")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<School> getAllSchool() throws Exception {
    	System.out.println("查询全部学校");
		return schoolService.getAllSchools();
    }

	@RequestMapping("/deleteSchoolBySno/{sno}")
	@ResponseBody
    public DTO<School> deleteSchoolBySno(@PathVariable("sno") String sno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(sno+"删除学校");
    	return schoolService.deleteSchoolBySno(sno);
    }

	@RequestMapping("/updateSchoolBySno")
	@ResponseBody
	public DTO<School> updateSchoolBySno( School school) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改学校");
		return schoolService.updateSchoolBySno(school);
	}


	@RequestMapping("/addSchool")
	@ResponseBody
	public DTO<School> addSchool(@RequestBody School school) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加学校");
		System.out.println(school);
 		return schoolService.addSchool(school);
	}
	@RequestMapping("/getSchoolByPage")
	@ResponseBody
	public DTO<School> getSchoolByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页管理员");
		return schoolService.getSchoolByPage(pageInfo);
	}

}